<?php
session_start();
date_default_timezone_set("Asia/Chongqing");
include("../common/connect.php");
include("../common/common.php");

$opt = trim(CheckUrlParamNoDie("opt"));
$showtype = trim(CheckUrlParamNoDie("showtype"));
$tag = CheckUrlParamNoDie("tag");
$id = CheckUrlParamNoDie("id");

if(isset($_POST["Site_Submit"]))
{
	$hdtitle = trim(GetPostParamStr("hdtitle"));
	$hdpic = trim(GetPostParamStr("hdpic"));
	$hdurl = trim(GetPostParamStr("hdurl"));
	$ntime = trim(GetPostParamStr("ntime"));
		
	if($id == "")
	{
		$sql = "insert into gwt_tab_hd (hdtitle,hdpic,hdurl,ntime) values ('$hdtitle', '$hdpic','$hdurl', '$ntime')";
		//insert into gwt_tab_hd (hdtitle,hdpic,hdurl,ntime) values('测试1', '1.jpg','http://www.gouweew.com', '2011-11-11 22:22:22')
		mysql_query($sql);
		echo "<script>window.history.go(-2);</script>";
	}
	else
	{
		$sql2 = "update gwt_tab_hd set hdtitle='$hdtitle', hdpic='$hdpic', hdurl='$hdurl', ntime='$ntime' where id=$id";
		mysql_query($sql2);
		if (mysql_affected_rows() == 1)
			echo "<script>window.history.go(-2);</script>";
	}
}

if ($opt == "del" && $id != "")
{
	mysql_query("delete from gwt_tab_hd where id=$id");
	if (mysql_affected_rows() == 1)
		echo "<script>window.history.go(-1);</script>";
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新建页面管理中心</title>
<style type="text/css">
body { font-size:12px;}
table,tr,th,td { margin:0; padding:0; color:#666;}
table { background:#09F;}
th { background:#BEF;}
th,td { padding:10px;}
tr { background:#fff;}
a { color:#00F;}
ul,ol,li { list-style:none;}
/***网站提交***/
.Unbound { background:#f2eeef; width:500px; padding:10px; position:absolute; top:10px; left:240px; font-size:12px;}
.Unbound .unss { background:#FFF; padding:10px; border:1px solid #999;}
.Unbound .sel { height:30px; border-bottom:1px solid #ddd;}
.Unbound .sel .Close a { float:right; text-indent:0; width:40px; display:inline-block;}
.Unbound .ted { overflow:hidden;}
.Unbound .ted .ted_tj { margin-top:10px;}
.Unbound .ted .ted_tj span { width:90px; text-align:right; display:block; float:left;}
.Unbound .ted .ted_tj .tedinp,.Unbound .ted .ted_tj textarea { height:22px; line-height:22px; border:1px solid #ddd; font-size:12px; padding:0 5px; color:#666; overflow:hidden;}
.Unbound .ted .ted_tj select.tedinp { padding:0;}
.Unbound .ted .ted_tj textarea { width:360px; height:70px; }
.Unbound .ted .sz_btn { margin:20px auto; width:133px; overflow:hidden;}
.Unbound .ted .sz_btn input { background:url(http://www.gouwutu.com/new/doc/img/sebtn.jpg) no-repeat; cursor:pointer; padding:0; color:#FFF; font-weight:bold; width:133px; height:45px; border:0;}
#recomtag ul { padding:0;}
</style>
</head>
<body>
<div style="background:#C00; font-size:16; height:30px; line-height:30px; text-align:center;"><a href="tab.php" style=" color:#FFF; font-weight:bold;">商城优惠活动管理</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="tabmsg.php" style=" color:#FFF;">底部消息管理</a></div>
<div style="padding:10px;"><a href="http://www.gouwutu.com/tab/index.php" target="_blank">点击打开新建页面</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="?opt=edit"><font color="#FF0000">添加商城优惠活动</font></a>&nbsp;&nbsp;&nbsp;&nbsp;
    <select  class="tedinp" name="Site_Tag" id="Site_Tag" size="1">
        <option value="1" selected='selected'>序列号</option>
        <option value="2">活动主题</option>
    </select>&nbsp;&nbsp;
    <input type="text" size="20" id="showtype" name="showtype" value="" style="width:200px;">&nbsp;&nbsp;
    <input type="button" value="查找" onclick="javascript:OnFind();">&nbsp;&nbsp;<a href="tab.php">默认显示</a>
</div>
<?php 
echo date("Y-m-d G:i:s");
?>
<table cellpadding="10" cellspacing="1" border="0" width="100%" style="color:red">
	<tr>
    	<th>序号</th>
    	<th>活动主题</th>
        <th>图片</th>
        <th>地址</th>
        <th>开始时间</th>
        <th>结束时间</th>
        <th>操作</th>
    </tr>
    <?php
    $sql='';
	if($showtype != "" && $tag == '1')
		$sql .= " where id=$showtype";
	if($showtype != "" && $tag == '2')
		$sql .= " where hdtitle='$showtype'";
	
	$sql = "select * from gwt_tab_hd".$sql;
	$result = mysql_query($sql);
	$i = 0;
	while( $result && $row = mysql_fetch_assoc($result))
	{
	?>
    <tr align="center">
    	<td><?php echo $row["id"]; ?></td>
    	<td><?php echo $row["hdtitle"]; ?></td>
        <td><img src="http://www.gouwutu.com/tab/pic/<?php echo $row["hdpic"]; ?>" alt="" /></td>
        <td><?php echo $row["hdurl"]; ?></td>
        <td><?php echo $row["stime"]; ?></td>
        <td><?php echo $row["ntime"]; ?></td>
        <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="?opt=edit&id=<?php echo $row["id"]; ?>">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:if(confirm('确实要删除吗?'))location='?opt=del&id=<?php echo $row["id"]; ?>'">删除</a>
    </tr>
    <?php } ?>
</table>
<?php 
if($opt == "edit")
{ 	
	//$siid = "";
	$hdtitle = "";
	$hdpic = "";
	$hdurl = "";
	$ntime = "";
	
	if( $id != "" )
	{
		$esql = "select * from gwt_tab_hd where id=$id limit 1";
		$eresult = mysql_query( $esql );
		if( $eresult && $row2 = mysql_fetch_assoc( $eresult ) )
		{
			//$siid = 
			$hdtitle = $row2["hdtitle"];
			$hdpic = $row2["hdpic"];
			$hdurl = $row2["hdurl"];
			$ntime = $row2["ntime"];
		}
	}
?>
<div style="display:block;" class="Unbound">
    <div class="unss">
        <div class="sel"><h2><span class="Close"><a href="tab.php">关闭</a></span>编辑/添加</h2></div>
        <div class="ted">
            <form onsubmit="return sunbmintSS()" method="post" action="tab.php?id=<?php echo $id; ?>" name="creator">
                <div class="ted_tj"><span>活动主题：</span><input type="text" value="<?php echo $hdtitle; ?>" name="hdtitle" id="hdtitle" maxlength="100" style="width:260px;" class="tedinp"></div>
                <div class="ted_tj"><span>图片：</span><input type="text" value="<?php echo $hdpic; ?>" name="hdpic" id="hdpic" maxlength="100" style="width:260px;" class="tedinp"></div>
                <div class="ted_tj"><span>地址：</span><textarea id="hdurl" name="hdurl" style=" width:260px; height:60px; overflow:hidden; font-size:12px;"><?php echo $hdurl; ?></textarea><!---<input type="text" value="" name="hdurl" id="hdurl" maxlength="100" style="width:260px;" class="tedinp">----></div>
                <div class="ted_tj"><span>结束时间：</span><input type="text" value="<?php echo $ntime; ?>" name="ntime" id="ntime" maxlength="100" style="width:260px;" class="tedinp"></div>
                <p class="sz_btn"><input type="submit" value="提 交" name="Site_Submit" id="Site_Submit"></p>
                <span><!-----奇怪的360 去掉设置就没有了------></span>
            </form>
        </div>
    </div>
</div>
<?php } ?>
</body>
</html>
<script type="text/javascript">
function OnFind()
{
	var site_tag = document.getElementById("Site_Tag").value;
	var input_tradeid = document.getElementById("showtype").value;
	window.location.href= "tab.php?showtype=" + input_tradeid + "&tag=" + site_tag ;
}
function sunbmintSS()
{
}
</script>
